package common.dao;


import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import com.dao.JdbcDAO;
import common.pojo.Hotel;

@Scope("prototype")
@Repository
public class HotelDAO extends JdbcDAO {

	
	public Hotel findInfo(){
		String sql ="select * from hotel ";
		return (Hotel)getObject(sql, null, new HotelInfoMapper());
	}
	
	/**
	 * 更新数据库
	 * @param hotel
	 * @return
	 */
	public boolean update(Hotel hotel){
		String sql ="update hotel set name=?,address=?" +
				",tel=?,summary=?,introduction=?,orderNote=?,traffic=?" ;
		update(sql,new Object[]{hotel.getName(),	hotel.getAddress(),	hotel.getTel(),hotel.getSummary(),
				hotel.getIntroduction(),hotel.getOrderNote(),hotel.getTraffic()});
		return true;
	}
	
	/**
	 * 映射私有类
	 * @author 
	 *
	 */
	private static final class HotelInfoMapper implements RowMapper {

		public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
			Hotel hotel = new Hotel();
			hotel.setId(rs.getInt(1));
			hotel.setName(rs.getString(2));
			hotel.setAddress(rs.getString(3));
			hotel.setTel(rs.getString(4));hotel.setSummary(rs.getString(5));
			hotel.setIntroduction(rs.getString(6));
			hotel.setOrderNote(rs.getString(7));
			hotel.setTraffic(rs.getString(8));
			return hotel;
		}
	}

}
